﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂.仓库.下线
{
    public partial class Form补录存货编码 : UIPage
    {
        public string 存货编号 { get; set; }
        //名称 品名 shortName +规格  INVSPEC  +材质  INVTYPE
        public string shortName { get; set; }
        public string INVSPEC { get; set; }
        public string INVTYPE { get; set; }
        public Form补录存货编码()
        {
            InitializeComponent();
        }

      

        private void Form补录存货编码_Load(object sender, EventArgs e)
        {
            uiTextBox存货名称.Text = shortName;
            uiTextBox规格.Text = INVSPEC;
            uiTextBox钢号.Text = INVTYPE;

            uiDataGridViewInventory.AutoGenerateColumns = false;
            //string sql = @"select distinct INVCLASSCODE T_GOOD_TYPE_CODE,INVCLASSNAME T_GOOD_TYPE from Dic_Inventory
            //            where INVCLASSNAME in ('酸洗卷', '轧硬卷', '镀锌卷', '冷扎卷', '彩涂卷', '硅钢卷', '镀铝锌卷', '无锌花镀锌卷', '彩基板')";
            string sql = "select distinct INVCLASSCODE T_GOOD_TYPE_CODE,INVCLASSNAME T_GOOD_TYPE from Dic_Inventory";
            DataTable dt = pub.GetDataTable(pub.ConnectionString, sql);
            uiDataGridViewInventoryClass.DataSource = dt;
        }

        private void uiDataGridViewInventoryClass_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
               DataTable dt = uiDataGridViewInventoryClass.DataSource as DataTable;
                string 分类 = dt.Rows[e.RowIndex]["T_GOOD_TYPE"].ToString();
                string 存货名称 = uiTextBox存货名称.Text;
                string 钢号 = uiTextBox钢号.Text;

                queryInv(分类,存货名称,钢号);
            }
        }

        private void queryInv(string 分类, string 存货名称, string 钢号)
        {
            string sqlQuery = @"select [guid], [INVCODE] T_GOOD_CODE,INVSHORTNAME, [INVNAME] T_GOOD_NAME,  [INVSPEC] T_GOOD_MODEL, [INVTYPE] T_GOOD_TYPE_CODE, 
                                [INVCLASSNAME] T_GOOD_TYPE from  Dic_Inventory
                                where 1=1 and INVCLASSNAME = '" + 分类.Trim() + "'";
            if (!string.IsNullOrEmpty(uiTextBox规格.Text.Trim()))
            {
                sqlQuery += "and INVSPEC = '"+ uiTextBox规格.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(uiTextBox钢号.Text.Trim()))
            {
                sqlQuery += "and INVTYPE = '" + uiTextBox钢号.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(uiTextBox存货名称.Text.Trim()))
            {
                sqlQuery += "and INVSHORTNAME = '" + uiTextBox存货名称.Text.Trim() + "'";
            }

            DataTable dt = pub.GetDataTable(pub.ConnectionString,sqlQuery);
            uiDataGridViewInventory.DataSource = dt;
            uiDataGridViewInventory.Refresh();
        }

        private void uiDataGridViewInventory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex == 0)
            {
                存货编号 = (uiDataGridViewInventory.DataSource as DataTable).Rows[e.RowIndex]["T_GOOD_CODE"].ToString();
                //this.DialogResult = DialogResult.OK;
                //this.Close();
            }
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            //DataTable dt = uiDataGridViewInventoryClass.DataSource as DataTable;
            //string 分类 = dt.Rows[e.RowIndex]["T_GOOD_TYPE"].ToString();
            //string 存货名称 = uiTextBox存货名称.Text;
            //string 钢号 = uiTextBox钢号.Text;

            //queryInv(分类, 存货名称, 钢号);
        }
    }
}
